const express = require("express");
const expressSession = require("express-session");
const app = express();
app.use(
  expressSession({
    secret: "ghol", //设置签名秘钥  内容可以随意填写
    cookie: {
      maxAge: 1000 * 60 * 60
    },
    resave: false, //强制保存
    saveUninitialized: false
  })
);
app.get("/add", (req, res) => {
  req.session.name = "tom";
  res.send("test session是否添加数据");
});
app.get("/select", (req, res) => {
  console.log(req.session);
  /* 
  Session {
  cookie: {
    path: '/',
    _expires: 2021-12-29T07:03:13.825Z,
    originalMaxAge: 3600000,
    httpOnly: true
  },
  name: 'tom'
}
  
  
  */
  res.send("查询到数据");
});
app.get("/del", (req, res) => {
  req.session.destroy();
  res.send("删除");
});

app.listen(3000, err => {
  if (!err) console.log("服务器启动");
  else console.log(err);
});
